package com.wuseguang.springcloud.service.impl;

import com.wuseguang.springcloud.dao.jdbc.TeacherChatJdbc;
import com.wuseguang.springcloud.service.TeacherChatService;
import com.wuseguang.springcloud.util.PinYinUtils;
import com.wuseguang.springcloud.util.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

@Service
public class TeacherChatServiceImpl implements TeacherChatService {


    private Logger logger = LoggerFactory.getLogger(this.getClass());


    @Autowired
    private TeacherChatJdbc teacherChatJdbc;


    @Override
    public Result queryStudentList(String schoolId, String teacherId, Integer classId) {

        logger.info("查询学生留言信息 TeacherChatServiceImpl - > queryStudentList");

        String sql = "SELECT t.id,t.student_name name,head_portrait headPortrait  FROM `student` t, teacher_chat b  " +
                "         WHERE t.school_id =? AND b.student_id=t.id AND b.teacher_id=? AND t.class_id=? AND b.type=0 AND b.state=0  GROUP BY t.id   ORDER BY CONVERT( name USING gbk ) ";


        List<Map<String, Object>> careList = teacherChatJdbc.queryListMap(sql, schoolId, teacherId, classId);

        Map<String, Object> mapList = new HashMap<>();
        logger.info("查询学生留言信息sql = {}", sql);

        sql = "SELECT t.id,t.student_name name,head_portrait headPortrait  FROM `student` t  WHERE t.school_id =? AND t.class_id=?";
        List<Map<String, Object>> list = teacherChatJdbc.queryListMap(sql, schoolId, classId);
        mapList.put("careList", careList);
        List<TreeMap<String, Object>> lists = PinYinUtils.px(list, "name");
        mapList.put("list", lists);
        //返回数据
        return new Result(mapList);
    }

}
